package d4_list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ListTest {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("三大的");
        list.add("撒大大");
        list.add("啊大大");
        list.add("发生发");
        System.out.println(list);

        list.add(2,"打赏");
        System.out.println(list);

        System.out.println(list.remove(2));
        System.out.println(list);

        System.out.println(list.get(3));

        System.out.println(list.set(3,"王八蛋"));

        //----------------------------------------------------------------------//

        //for循环
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

        //迭代器
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }

        //增强for循环
        for (String string : list) {
            System.out.println(string);
        }

        //foreach
        list.forEach(s->System.out.println(s));
    }
}
